#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @Project:     python_framework
# @File:        u_redis.py
# @Author:      Fan GuiChuan
# @Date:        2024/7/4 16:24
# @Version:     Python3.7
# @Description: Redis管理类
import threading
import redis


class RedisManager(object):
    __instance_lock = threading.Lock()
    __redis_pool = None

    @classmethod
    def get_redis(cls):
        if cls.__redis_pool is None:
            with cls.__instance_lock:
                cls.__redis_pool = redis.ConnectionPool(host='127.0.0.1', port='6379', db=0)

        _redis = redis.Redis(connection_pool=cls.__redis_pool)
        return _redis


if __name__ == '__main__':
    r = RedisManager.get_redis()
    print(f"keys: {r.keys()}")
